<template>
	<div>
		<div v-if="showEncryption">
			<el-dialog title="申请文件解密" append-to-body :visible.sync="showEncryption" width="36%">
				<el-form :model="form" ref="form" size="small">
					<el-form-item label="申请解密的文件:" prop="name">
						<div>
							<div class="f14" v-for="item in list">{{ item.name }}</div>
						</div>
					</el-form-item>
					<el-form-item label="解密用途:" prop="content" :rules="[{ required: true, message: '请选择文件用途' }]">
						<el-select class="w160" placeholder="请选择" v-model="form.content" filterable :disabled="isSubmit">
							<el-option v-for="item in applyList" :key="item.value" :value="item.value" :label="item.value"></el-option>
						</el-select>
					</el-form-item>
					<el-row>
						<el-col :span="12">
							<el-form-item label="申请部门:"><el-input v-model="userInfo.deptName" class="w160" readonly></el-input></el-form-item>
						</el-col>
						<el-col :span="12">
							<el-form-item label="申请人:"><el-input v-model="userInfo.real_name" class="w160" readonly></el-input></el-form-item>
						</el-col>
						<el-col :span="24" v-if="isSubmit">
							<div class="main_co flex_center"><span>提交申请成功,文件解密中.....</span></div>
						</el-col>
					</el-row>
				</el-form>
				<span slot="footer" class="dialog-footer flex_center">
					<el-button type="primary" size="small" @click="submitApply" v-if="!isSubmit">提交申请</el-button>
					<el-button type="primary" size="small" @click="close()" v-else>确定</el-button>
				</span>
			</el-dialog>
		</div>
	</div>
</template>

<script>
import { applyDecrypt } from '@/api/myapi/common';
export default {
	props: {
		list: {
			type: Array,
			default() {
				return [];
			}
		}
	},
	data() {
		return {
			applyList: [
				{
					value: '查看/打印'
				},
				{
					value: '查看/快捷新增'
				}
			],
			showEncryption: false,
			isSubmit: false,
			form: {
				applyStatus: 0,
				content: ''
			}
		};
	},
	created() {
		let matched = this.$route.matched;
		console.log(this.$parent.processType);
		if (this.$parent.processType == '') {
			this.form.content = '查看/打印';
			this.applyList[1].value = '查看/升版';
		}
		if (matched[0].path.indexOf('guifanwenjian') > 0 || matched[0].path.indexOf('jiluwenjian') > 0) {
			this.applyList.push({
				label: 0,
				value: '查看/新增记录'
			});
		}
	},
	methods: {
		init() {
			this.showEncryption = true;
		},
		close() {
			this.showEncryption = false;
			this.isSubmit = false;
			setTimeout(() => {
				let pageNo = this.$parent.pageNo;
				this.$parent.refreshList(pageNo);
			}, 300);
		},
		//   提交申请解密
		submitApply() {
			console.log(this.processId);
			this.$refs.form.validate(valid => {
				if (valid) {
					applyDecrypt({
						decryptFilesList: this.list,
						processId: this.$parent.processId,
						decryptUser: this.$parent.privateKeyHolder,
						processType: this.$parent.processType,
						gongzuoFilesId: this.$parent.gongzuoFilesId,
						...this.form
					}).then(({ data }) => {
						console.log(data);
						if (data.code == 200) {
							this.isSubmit = true;
						}
					});
				}
			});
		}
	}
};
</script>

<style></style>
